package com.example.system.controller;

import com.example.reception.entity.Order;
import com.example.reception.entity.Products;
import com.example.reception.entity.User;
import com.example.system.model.ApiResponse;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * author: adnaan
 * create: 2023-11-15 19:51
 * Description:
 */
@RestController
@RequestMapping("/adminHome")
public class HomeController {

    @Resource
    private MongoTemplate mongoTemplate;


    @GetMapping("/detail")
    public ApiResponse detail(){
        Query query = new Query();
        Long userTotal = mongoTemplate.count(query,User.class);
        Long prodTotal = mongoTemplate.count(query, Products.class);
        Long orderTotal = mongoTemplate.count(query, Order.class);
        Map<String, Object> res = new HashMap<>();
        res.put("userTotal",userTotal);
        res.put("prodTotal",prodTotal);
        res.put("orderTotal",orderTotal);

        return ApiResponse.success(res);
    }
}
